

/* ajax callback*/
var reply = function(data){
if (data != null) {
		try{
			var fun=data["callback"];
			eval(fun+"(data)");
		}catch(e){}
		
	}
}
//获得页面所有数据(id),返回json
function getAllParam(){
	var result=new Object();
	//1.遍历input
	$("input").each(function(){
		var type=$(this).attr("type").toLowerCase();
		var name=$(this).attr("name").toLowerCase();
		if(type=="text"){
			//输入框
			var val=$(this).val();
			result[name]=val;
		}else if(type=="hidden"){
			//hidden
			var val=$(this).val();
			result[name]=val;
		}else if(type=="password"){
			//password
			var val=$(this).val();
			result[name]=val;
		}else if(type=="file"){
			//file
			var val=$(this).val();
			result[name]=val;
		}else if(type=="radio"){
			//单选框
			var val=getRadioValue(name);
			result[name]=val;
		}else if(type=="checkbox"){
			//多选框
			var val=getCheckboxValue(name);
			result[name]=val;
		}
	});
	
	//1.遍历select
	$("select").each(function(){
		var name=$(this).attr("name").toLowerCase();
		var val=$(this).val();
		result[name]=val;
	});
	
	//1.遍历textarea
	$("textarea").each(function(){
		var name=$(this).attr("name").toLowerCase();
		var val=$(this).val();
		result[name]=val;
	});
	return result;
	
}

//提交
function submitCommon(param,name,refun){
	if(refun==undefined||refun=="") {
		refun="doCommonReturn";
	}
	eval("dwrClass.commonAjax(name,param,refun,{callback:reply,exceptionHandler:exceptionHandler})");
}
//提交
function submitCore(param,name,refun){
	if(refun==undefined||refun=="") {
		refun="doCommonReturn";
	}
	eval("dwrClass.coreAjax(name,param,refun,{callback:reply,exceptionHandler:exceptionHandler})");
}
//提交
function submitUpload(name,ispic,fun){
	var val=$("#"+name).val();
	if(val==""){
		atInfo("请选择上传文件!");
	}else{
		var no=(new Date()).getTime();
		var action=base+"/upload.do?no="+no+"&ispic="+ispic+"&fun="+fun;
		var form1="form_1";
		$("#"+form1).attr("action",action);
		$("#"+form1).submit();
		//每1秒执行 
		$("body").everyTime("1s","upload",function(){
			var param=new Object();
			param["no"]=no;
			submitCommon(param,"getUploadProgress","doGetUploadProgress");
		}); 
	}
}
function doGetUploadProgress(data){
	var flag=data["flag"];
	var errFlag=data["errFlag"];
	if(errFlag==1){
		if(flag>=100){
			$('body').stopTime('upload');
			//获得信息
			doAddFile(data);
			parent.$("#img").val("");
		}
		try{
			uploadProgressReturn(flag);
		}catch(e){}
	}else{
		parent.$("#img").val("");
		$('body').stopTime('upload');
		parent.atPageClose("upload");
		parent.$("#img").val("");
		try{
			uploadProgressReturn(-1);
		}catch(e){}
		var msg=getCommonMsg(errFlag);
		parent.atInfo(msg,function(){parent.atPageClose("upload");});
	}
	
}


//获得信息
function getCommonMsg(flag){
	var msg="";
	if(flag==0){
		msg="未知错误!";
	}else if(flag==1){
		msg="操作成功!";
	}else if(flag==2){
		msg="操作失败!";
	}else if(flag==3){
		msg="您还没有登录，请先登录!";
	}else if(flag==4){
		msg="您不是管理员，不能进行操作!";
	}else if(flag==6){
		msg="用户或密码不正确!";
	}else if(flag==7){
		msg="账号被冻结!";
	}else if(flag==8){
		msg="旧密码不正确!";
	}else if(flag==10){
		msg="用户名已存在!";
	}else if(flag==11){
		msg="学号已存在!";
	}else if(flag==12){
		msg="身份证已存在!";
	}else if(flag==20){
		msg="主讲老师才能操作!";
	}else if(flag==1000){
		msg="由于长时间未进行操作,请先登录!";
	}else if(flag==1001){
		msg="请求方法不存在!";
	}else if(flag==1002){
		msg="超级管理员才能进行操作!";
	}
	return msg;
}

//获得出错信息
function getErrMsg(name){
	var msg="请先登录";
	if(name=="AdminRoleException"){
		msg="由于长时间未进行操作,请先登录!";
	}else if(name=="AdminSuperRoleException"){
		msg="只有超级管理员才能进行操作!";
	}
	return msg;
}

//异常返回
function exceptionHandler(errorString,exception){
	var name=exception["cause"].message;
	var msg=getErrMsg(name);
	var url=base+"/index.htm";
	atInfo(msg,function(){location.href=url;});
}
//普通返回
function doCommonReturn(data){
	var flag=data["flag"];
	if(flag==1){
		parent.reloadAjax();
		parent.showSuccess();
		try{
			parent.atPageClose();
		}catch(e){}
		return;
	}else{
		var msg=getCommonMsg(flag);
		parent.atInfo(msg);
	}
}
function doCommonReturn1(data){
	var flag=data["flag"];
	if(flag==1){
		parent.reloadAjax1("showajaxinfo1");
		parent.showSuccess();
		try{
			parent.atPageClose();
		}catch(e){}
		return;
	}else{
		var msg=getCommonMsg(flag);
		parent.atInfo(msg);
	}
}

function doCommonReloadReturn(data){
	var flag=data["flag"];
	var msg="";
	if(flag==1){
		parent.location.reload();
		return;
	}else{
		msg=getCommonMsg(flag);
		parent.atInfo(msg);
	}
}
function doCommonReloadOkReturn(data){
	var flag=data["flag"];
	var msg="";
	if(flag==1){
		parent.atInfo("信息操作成功",function(){parent.location.reload();});
		return;
	}else{
		msg=getCommonMsg(flag);
		parent.atInfo(msg);
	}
}
function doCommonDeleteReturn(data){
	var flag=data["flag"];
	var msg="";
	if(flag==1){
		hideDelete("msg_"+data["id"]);
		return;
	}else{
		msg=getCommonMsg(flag);
		parent.atInfo(msg);
	}
}
function doCommonSuccessReturn(data){
	var flag=data["flag"];
	var msg="";
	if(flag==1){
		try{
			parent.reloadAjax();
		}catch(e){}
		parent.showSuccess();
		return;
	}else{
		msg=getCommonMsg(flag);
		parent.atInfo(msg);
	}
}
function doAjaxReturn(data){
	reloadAjax();
}

function doCommonPopReturn(data){
	var flag=data["flag"];
	var msg="";
	if(flag==1){
		var pageiframe=$("#pageiframe");
		var url=$("#pageiframe",parent.document.body).attr("src"); 
		$("#pageiframe",parent.document.body).attr("src",url); 
		return;
	}else{
		msg=getCommonMsg(flag);
		parent.atInfo(msg);
	}
}


